package com.kyleswebspace.util;

import java.util.Scanner;

public class Financial {
	

	public static long getYear1PPD(long principal, long monthlyPayment, double intRate) {
		double a, b; 
		long total = 0;
		
		for(int i = 0; i < 12; i++) {
			a = (((principal * intRate)/360)*30);
			b = monthlyPayment - a;
			total += b;
			principal -= b;
		}
		
		return total;
	}
	
	public static double getCumPrincipal(double intr, int NPer, int PV, int start, int end, boolean Due) {
		double payment = 0, total = 0;
		double principal = PV;
		
		for (int i = 1; i <= end; i++ ) {
			payment = getPPMT(intr, i, NPer, PV, 0, Due);
			total += payment;
			principal -= payment;
		}
		
		return total;
	}
	
	public static double getPMT(double intRate, int numPayments, int PV) {
		double a = (PV * Math.pow(1 + intRate, numPayments)) * intRate;
		double b = 1 - Math.pow(1 + intRate, numPayments);
		
		return -(a/b);
	}
	
	public static double getPPMT(double intr, int Per, int NPer, double PV, int FV, boolean Due) {
		double float1 = Per - (Due?2:1);
		double float2 = - FV*intr/((Math.pow(1+ intr,NPer)- 1)*(Due?1+ intr:1))+ - PV/((Due?1:0)+ 1/intr*(1- 1/Math.pow(1+ intr,NPer- (Due?1:0))));
		return ((- FV*intr/((Math.pow(1+ intr,NPer)- 1)*(Due?1+ intr:1))+ - PV/((Due?1:0)+ 1/intr*(1- 1/Math.pow(1+ intr,NPer- (Due?1:0))))- - (PV*Math.pow(1+ intr,float1)- (- 0*Math.pow(1+ intr,float1)+ - (1/intr)*float2*(Math.pow(1+ intr,float1)- 1)*(Due?1+ intr:1)- (Due?float2:0)))*intr)*-1);
	}
}
